/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uy.edu.ort.persistencia;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;
import uy.edu.ort.dominio.Programa;
import uy.edu.ort.persistencia.util.HibernateUtil;

/**
 *
 * @author Santiago
 */
public class GenericDAO {  

    private Session sesion; 
    private Transaction tx;  

     
    public void borrarProgramas() throws HibernateException 
    { 
       
        try {
            iniciaOperacion();
            String consulta = "DELETE FROM Programa";
            sesion.createQuery(consulta);
        } finally {
            sesion.close(); 
        }
               
    }
    
     public void borrarClientes() throws HibernateException 
    { 
       
        try {
            iniciaOperacion();
            String consulta = "DELETE FROM Cliente";
            sesion.createQuery(consulta);
        } finally {
            sesion.close(); 
        }
               
    }
     
      public void borrarPaginas() throws HibernateException 
    { 
       
        try {
            iniciaOperacion();
            String consulta = "DELETE FROM Pagina";
            sesion.createQuery(consulta);
        } finally {
            sesion.close(); 
        }
               
    }
    
  
    
    private void iniciaOperacion() throws HibernateException 
    { 
        sesion = HibernateUtil.getSessionFactory().openSession(); 
        tx = sesion.beginTransaction(); 
    }  

    private void handleException(HibernateException he) throws HibernateException 
    { 
        tx.rollback(); 
        throw new HibernateException("Ocurrió un error en la capa de acceso a datos", he); 
    }
    
}


